package com.beehoo.dcportal.admin.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.beehoo.dcportal.admin.dao.WorkerDao;
import com.beehoo.dcportal.common.base.BaseDao;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.model.FunctionBean;
import com.beehoo.dcportal.model.WorkerBean;

public class WorkerDaoImpl extends BaseDao implements WorkerDao {

	private static final Logger logger = Logger.getLogger(WorkerDaoImpl.class);

	@Override
	public WorkerBean queryUserByNP(Map<String, Object> paramMap)
			throws BaseException {
		WorkerBean workerBean = null;
		try {
			workerBean = (WorkerBean) sqlMapClient.queryForObject(
					"Worker.queryUserByNP", paramMap);
			logger.info("用户登录-根据用户名和密码查询用户|#[用户名：" + paramMap.get("loginName")
					+ "],[密码：" + paramMap.get("password") + "],成功!");
		} catch (SQLException e) {
			logger.error("用户登录-根据用户名和密码查询用户|#" + "[用户名："
					+ paramMap.get("loginName") + "],[密码："
					+ paramMap.get("password") + "]" + "失败!异常："
					+ e.getMessage());
			throw new BaseException(e, "custom.messages.error.user.login.error");
		}
		return workerBean;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<FunctionBean> queryFunction(String roleId) throws BaseException {
		List<FunctionBean> functionLs = null;
		try {
			functionLs = sqlMapClient.queryForList("Worker.queryFunction", roleId);
			logger.info("用户登录-查询用户功能菜单|#" + "[用户权限：" + roleId + "成功!");
		} catch (SQLException e) {
			logger.error("用户登录-查询用户功能菜单|#" + "[用户权限：" + roleId 
					+ "失败!异常：" + e.getMessage());
			throw new BaseException(e, "custom.messages.error.user.function.error");
		}
		return functionLs;
	}

}
